package com.lzh.java9;

import org.junit.Test;

import java.util.*;

/**
 * @author liuzhihao
 * @create 2021-02-23 13:40
 */
public class MapTest {

    @Test
    public void test1(){

        Map<Integer,String> map = new HashMap<>();
        map.put(1,"liuzhihao");
        map.put(2,"haha");
        map.put(3,"asdf");

//        Set<Integer> set = map.keySet();
//        for(Integer i : set){
//            System.out.println(i);
//        }
//
//        Collection<String> values = map.values();
//        for(String v : values){
//            System.out.println(v);
//        }
//
//        System.out.println();

//        Set<Integer> set = map.keySet();
//        Iterator<Integer> iterator = set.iterator();
//        while(iterator.hasNext()){
//            Integer key = iterator.next();
//            String value = map.get(key);
//            System.out.println(key+"----" + value);
//
//        }

        Set<Map.Entry<Integer, String>> entrySet = map.entrySet();
        Iterator<Map.Entry<Integer, String>> iterator = entrySet.iterator();
        while(iterator.hasNext()){
            Map.Entry<Integer, String> entry = iterator.next();
            Integer key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"----"+value);
        }
    }
    @Test
    public void test2(){
        ArrayList<Integer> list = new ArrayList<>();
        list.add(123);
        list.add(456);
        list.add(7889);

        Iterator<Integer> iterator = list.iterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }

    @Test
    public void test3(){
        HashMap<String,String> map = new HashMap<String,String>();
        map.put("123","asd");
        map.put("456","qwer");
        map.put("789","zxcv");

        List<String> list1 = print(map);
        for(String s : list1){
            System.out.println(s);
        }


    }
    public List<String> print(HashMap<String,String> map){
        ArrayList<String> list = new ArrayList<>();
        Collection<String> values = map.values();
        for(String s : values){
            list.add(s);
        }
        return list;
    }


}
